Print one to n


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and print number one to n

function print(n) {

}

print(1);
// 1

print(3);
// 1
// 2
// 3

print(9);
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9

Answer:

function print(n) {
  for (let i = 1; i <= n; i++) {
    console.log(i);
  }
}

print(1);
print(3);
print(9);









Related Posts

[day-11] JS 陣列 forEach 資料處理方法

[day-11] JS 陣列 forEach 資料處理方法

ALT 圖片替代文字

ALT 圖片替代文字

[cmd] 怎麼使用 command line 來 kill 正在某個 port 上面的 process?

[cmd] 怎麼使用 command line 來 kill 正在某個 port 上面的 process?


Comments